package com.woniu.houtai.config;

import com.woniu.houtai.interceptors.JwtRenewInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration  //指明当前类是配置类
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    JwtRenewInterceptor jwtRenewInterceptor;


    //registry  注册表
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //WebMvcConfigurer.super.addViewControllers(registry);

        //注册 路径和视图的匹配关系
        registry.addViewController("/").setViewName("homev");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/register.html").setViewName("register");
        registry.addViewController("/addShop.html").setViewName("addShop");
        registry.addViewController("/myOrder.html").setViewName("myOrder");
        registry.addViewController("/product.html").setViewName("product");
        registry.addViewController("/dataPanel.html").setViewName("dataPanel");
        registry.addViewController("/reply.html").setViewName("reply");
        registry.addViewController("/work3.html").setViewName("work3");
        registry.addViewController("/homev.html").setViewName("homev");
        registry.addViewController("/Myshop.html").setViewName("Myshop");
        registry.addViewController("/addProduct.html").setViewName("addProduct");
        registry.addViewController("/shopDetail.html").setViewName("shopDetail");
        registry.addViewController("/updatePassword.html").setViewName("updatePassword");
        registry.addViewController("/updatePassword.html").setViewName("updatePassword");
        registry.addViewController("/businessDetail.html").setViewName("businessDetail");

        //张朝朝
        registry.addViewController("/order.html").setViewName("order");
        registry.addViewController("/outOrder.html").setViewName("outOrder");
        registry.addViewController("/waitOrder.html").setViewName("waitOrder");
        registry.addViewController("/voice.html").setViewName("voice");
        registry.addViewController("/myProducts.html").setViewName("myProducts");





    }


    @Override
    public void addInterceptors(InterceptorRegistry registry){

        List<String> exclude=new ArrayList<>();

        exclude.add("/**/*login*/**");

        exclude.add("/**/*register*/**");

        exclude.add("/**/*success*/**");

        exclude.add("/**/*error*/**");

        exclude.add("/**/*dataPanel*/**");

        exclude.add("/**/*confirm*/**");

        exclude.add("/**/*business*/**");

        exclude.add("/**/*.png");

        exclude.add("/**/*.js");

        exclude.add("/**/*.css");

        exclude.add("/**/*.jpg");

        registry.addInterceptor(jwtRenewInterceptor).addPathPatterns("/**").excludePathPatterns(exclude);
        //registry.addInterceptor(loginInterceptor()).addPathPatterns("/**").excludePathPatterns(exclude);




    }



}
